package com.taptech.doufu.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.taptech.doufu.presenter.BasePresenter

abstract class BaseMvpFragment <P:BasePresenter<*>>:DiaobaoBaseFragment(){


    protected lateinit var mPresenter: P

    protected abstract fun initPresenter()

    protected abstract fun getLayout():Int

    protected abstract fun initView(rootView: View)



    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater?.inflate(getLayout(), container, false)
        initPresenter()
        checkPresenterIsNull()
        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView(view?:View(context))
    }

    private fun checkPresenterIsNull() {
        if (mPresenter == null) {
            throw IllegalStateException("please init mPresenter in initPresenter() method ")
        }
    }

}